package ren.kane.phoenix.redis;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author renrk(1275) on 2018-10-12 8:12 PM
 **/
@CrossOrigin
@RestController
@RequestMapping("/phoenix/redis")
@Api(value = "Redis控制类", description = "Redis的相关接口API")
public class RedisController {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @PostMapping("/set")
    @ApiOperation(value = "存值", httpMethod = "POST")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "query", dataType = "string", name = "key", value = "键", required = true),
        @ApiImplicitParam(paramType = "query", dataType = "string", name = "value", value = "值", required = true)})
    public void set(@RequestParam("key") String key, @RequestParam("value") String value) {
        redisTemplate.opsForValue().set(key, value);
        stringRedisTemplate.opsForValue().set(key + "string", value);
        System.out.println(stringRedisTemplate.opsForValue().get(key));
    }
}
